import React,{useState,useEffect} from 'react'
import {
  useDispatch, //派发仓库
  useSelector  //获取仓库数据
 } from 'react-redux'
import * as api from '../../api/index'

function Shou() {

  const dispatch=useDispatch()

  //把数据派送到store仓库数据
  useEffect(()=>{
    dispatch(api.getList())
  },[dispatch]) 

  //取reduce 的仓库数据 list
  const list =useSelector((state)=>{
    console.log(state)
    return state.reduce.list
  })  
  console.log(list)
  return (
    <div>
        {
          list && list.length >0 ? list.map((item,index)=>{
            return <div key={index} className="son">
              <img src={item.img}/>
              <span>{item.title}</span>
            </div>
          }):'暂无数据'
        }
    </div>
  )
}

export default Shou